package com.zsz.springboot.web;

import com.zsz.springboot.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "/user")
public class UserController {

    //用户登录的请求
    //需要排除
    @RequestMapping(value = "/login")
    @ResponseBody
    public Object login(HttpServletRequest request){

        //将用户的信息存放到session中
        User user=new User();
        user.setId(1001);
        user.setUsername("lisi");
        request.getSession().setAttribute("user",user);

        return "login Success";
    }


    //该请求需要用户登录之后才能访问
    @RequestMapping(value = "/center")
    @ResponseBody
    public Object center(){


        return "see center message";
    }



    //该请求不登录也可访问
    @RequestMapping(value = "/out")
    @ResponseBody
    public Object out(){

        return "out see anyTime";

    }



    //如果用户未登录访问了需要登录才访问的请求，之后会跳转至该请求路径
    //该请求路径不需要用户登录也可以访问
    @RequestMapping(value = "/error")
    @ResponseBody
    public Object error(){

        return "error";

    }






















}
